﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TCM.Models;

namespace TCM.Controllers
{
    public class FormController : Controller
    {
        private TCMContext db = new TCMContext();

        //
        // GET: /Form/

        public ActionResult Index()
        {
            return View(db.FORMSBASEs.ToList());
        }

        //
        // GET: /Form/Details/5

        public ActionResult Details(Guid ?id = null)
        {
            FORMSBASE formsbase = db.FORMSBASEs.Find(id);
            if (formsbase == null)
            {
                return HttpNotFound();
            }
            return View(formsbase);
        }

        //
        // GET: /Form/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Form/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(FORMSBASE formsbase)
        {
            if (ModelState.IsValid)
            {
                formsbase.FORMID = Guid.NewGuid();
                db.FORMSBASEs.Add(formsbase);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(formsbase);
        }

        //
        // GET: /Form/Edit/5

        public ActionResult Edit(Guid ?id = null)
        {
            FORMSBASE formsbase = db.FORMSBASEs.Find(id);
            if (formsbase == null)
            {
                return HttpNotFound();
            }
            return View(formsbase);
        }

        //
        // POST: /Form/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(FORMSBASE formsbase)
        {
            if (ModelState.IsValid)
            {
                db.Entry(formsbase).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(formsbase);
        }

        //
        // GET: /Form/Delete/5

        public ActionResult Delete(Guid ?id = null)
        {
            FORMSBASE formsbase = db.FORMSBASEs.Find(id);
            if (formsbase == null)
            {
                return HttpNotFound();
            }
            return View(formsbase);
        }

        //
        // POST: /Form/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(Guid id)
        {
            FORMSBASE formsbase = db.FORMSBASEs.Find(id);
            db.FORMSBASEs.Remove(formsbase);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}